<?php echo $this->Html->script('endereco'); ?>
<fieldset  style="border: 1px solid #c5c5c5;">
    <legend>Endereço(s)</legend>
    <table width="100%" id="tbEnderecos">
        <tr>
            <th colspan="2">
                <?php echo $this->Form->input('', array('type' => 'select', 'label' => 'Tipo', 'id' => 'selTipoEndereco', 'class' => 'box100', 'options' => array('R' => 'Residencia', 'T' => 'Trabalho') )); ?>
            </th>
            <th colspan="2">
                <?php echo $this->Form->input('', array('type' => 'text', 'label' => 'CEP', 'id' => 'txtCEP', 'class' => 'campoCEP', 'size' => "10", 'maxlength' => "10")); ?>
            </th>
            <th colspan="4">
                <?php echo $this->Html->image('/img/incluir.png', array('id' => 'btnAdicionar', 'onclick' => 'AdicionarEndereco();')) ?>
            </th>
        </tr>
        <tr>
            <th colspan="4">
                <?php echo $this->Form->input('', array('type' => 'select', 'label' => 'Cidade', 'id' => 'cdCIDADE', 'options' => $arrCidade )); ?>
            </th>
            <th colspan="2">
                <?php echo $this->Form->input('', array('type' => 'select', 'label' => 'UF', 'id' => 'cdUF', 'options' => $arrUF )); ?>
            </th>
            <th colspan="4">
                <?php echo $this->Form->input('', array('type' => 'select', 'label' => 'Pais', 'id' => 'cdPAIS', 'options' => $arrPais )); ?>
            </th>
        </tr>
        <tr>
            <th colspan="8">
                <?php echo $this->Form->input('', array('type' => 'text', 'label' => 'Logradouro', 'id' => 'txtLogradouro', 'class' => 'campoAlfa', 'size' => "10", 'maxlength' => "50")); ?>
            </th>
        </tr>
        <tr>
            <th colspan="8">
                <?php echo $this->Form->input('', array('type' => 'text', 'label' => 'Bairro', 'id' => 'txtBairo', 'class' => 'campoAlfa', 'size' => "10", 'maxlength' => "20")); ?>
            </th>
        </tr>
        <tbody id="listaEnderecos">
            <?php
            $enderecos = $this->request->data('ENDERECOS');
            if (isset($enderecos)):
                $index = 0;
                $usuarios = $this->Session->read('usuario');
                foreach ($enderecos as $tele):
                    ?>
                    <tr>
                        <td>
                            <?php echo $this->Form->input('', array('type' => 'radio', 'label' => false, 'options' => array('S'=>''), 'checked' => (($tele['ST_PRINCIPAL'] === 'S') ? true : false) )) ?>
                        </td>
                        <td>
                            <?php echo $this->Form->input('', array('type' => 'hidden', 'label' => false, 'value' => $tele['CO_ENDERECO'])) ?>
                            <?php echo $this->Form->input('', array('type' => 'hidden', 'label' => false, 'value' => $tele['TP_ENDERECO'])) ?>                            
                            <?php echo $this->Siscel->tipoTelefone($tele['TP_ENDERECO']); ?>
                        </td>
                        <td>
                            <?php echo $this->Form->input('', array('type' => 'hidden', 'label' => false, 'value' => $tele['NU_CEP'])) ?><?php echo $tele['NU_CEP']; ?>
                        </td>
                        <td>
                            <?php echo $this->Form->input('', array('type' => 'hidden', 'label' => false, 'value' => $tele['CD_CID'])) ?><?php echo $tele['NM_CID'].'/'.$tele['NM_UF']; ?>
                            <?php echo $this->Form->input('', array('type' => 'hidden', 'label' => false, 'value' => $tele['CD_UF'])) ?>
                        </td>
                        <td>   
                            <?php echo $this->Form->input('', array('type' => 'hidden', 'label' => false, 'value' => $tele['CD_PAIS'])) ?><?php echo $tele['NM_PAIS']; ?>
                        </td>
                        <td>
                            <?php echo $this->Form->input('', array('type' => 'hidden', 'label' => false, 'value' => $tele['DS_LOGRADOURO'])) ?><?php echo $tele['DS_LOGRADOURO']; ?>
                        </td>
                        <td>
                            <?php echo $this->Form->input('', array('type' => 'hidden', 'label' => false, 'value' => $tele['DS_BAIRRO'])) ?><?php echo $tele['DS_BAIRRO']; ?>
                        </td>
                        <td>
                            <img src='/siscel/img/bt_apagar.gif'  id='btnExcluir<?php echo $index ?>' class='btnExcluir' onclick="deletarEndereco(<?php echo $tele['CO_ENDERECO'] ?>, this)"/>
                        </td>
                    </tr>
                    <?php
                    $index++;
                endforeach;
            endif;
            ?>
        </tbody>
    </table>
</fieldset>
<script language="javascript">
    function Excluir(idImg) {
        var par = $('#' + idImg).parent().parent(); //tr
        par.remove();
    }
    ;
    function Excluir(idImg) {
        var par = $('#' + idImg).parent().parent(); //tr
        par.remove();
    }
    ;
</script>